package exercise2;
import java.util.Scanner;
public class Exercise02_06 {
    public static void main(String []args)
    {
        Scanner input =new Scanner(System.in);
        System.out.println("Enter a number between 0-1000: ");
        int digit=input.nextInt();

        int l=(digit+"").length();//求整数长度
        int[] num=new int[l];//定义一个存放数字的数组
        int i=0;//作为循环变量
        while (digit>10)
        {
            num[i]=digit%10;
            digit=digit/10;
            i++;
        }
        num[i]=digit;//加上最后一位

        int sum=0;
        for(int j=0;j<l;j++)
        {
            sum=sum+num[j];
        }
        System.out.println("The sun of the digit is "+sum);
    }
}
